<?php

namespace app\models;

use yii\db\ActiveRecord;

/**
 * @property int flow_id
 * @property int project_id *
 * @property int projectType
 * @property mixed flow
 * @property mixed project
 * @property mixed projecttype
 */
class FlowType extends ActiveRecord
{
    public static function tableName()
    {
        return '{{%flow_type}}';
    }
    /** ------------------------- 验证规则，字段输入输出规则  -------------------------------*/
    // 使用load 与 save 方法时此规则会起作用
    // 此规则必须配置，否则字段不能load到模型的属性。
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['complete_at', 'status', 'flow_at', 'project_id', 'flow_id', 'valid', 'checkStatus'], 'integer'],
        ];
    }

    public function getProject(){
        return $this->hasOne(Project::class, ['id' => 'project_id']);
    }

    public function getFlow(){
        return $this->hasOne(Flow::class, ['id' => 'flow_id']);
    }


    public function extraFields()
    {
        $fields['name'] = function(){
          return  $this->flow->name !== null ? $this->flow->name : null;
        };
        $fields['complete_at'] = function(){
            return  $this->project->complete_at !== null ? $this->project->complete_at : null;
        };
        $fields['checker'] = function(){
            return  $this->project->checker !== null ? $this->project->checker : null;
        };
        $fields['proofreader'] = function(){
            return  $this->project->proofreader !== null ? $this->project->proofreader : null;
        };
        return $fields;
    }
}
